package com.hitechbangla.fctu.utility;

import com.hitechbangla.fctu.base.GameScene;
import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFileChooser;

/**
 *
 * @author deb kanti
 */

public class RecordedGame implements Serializable
{
    private List<RecordedGameListValue> listRecordedGame;
    private long startTime; // every time variable will store miliseconds in this class
    private RecordingState recordingState;
    
    public RecordedGame()
    {
	listRecordedGame = new ArrayList<>();
	startTime = System.currentTimeMillis();
	recordingState = RecordingState.STARTED;
    }
    
    public List<Long> getAllTime()
    {
	List<Long> listTime = new ArrayList<>();
	
	for(int i=0;i<this.size();i++)
	{
	    listTime.add(listRecordedGame.get(i).getTime());
	}
	
	return listTime;
    }
    
    public List<GameScene> getAllGameScene()
    {
	List<GameScene> listGameScene = new ArrayList<>();
	
	for(int i=0;i<this.size();i++)
	{
	    listGameScene.add(CustomSerializer.stringToObject(listRecordedGame.get(i).getStrGameScene()));
	}
	return listGameScene;
    }

    public int size()
    {
	return listRecordedGame.size();
    }
    
    
    public boolean isRecordingStarted()
    {
	return (recordingState == RecordingState.STARTED);
    }
    
    public void stopRecording()
    {
	recordingState = RecordingState.STOPPED;
    }
    
    public void storeGameScene(GameScene gameScene)
    {
	long currentTime = System.currentTimeMillis();	
	RecordedGameListValue recordedGameListValue = new RecordedGameListValue(currentTime-startTime, CustomSerializer.objectToString(gameScene));
	listRecordedGame.add(recordedGameListValue);
	//System.out.println("from recordedgame: value put");
	//System.out.println("record size:" + listRecordedGame.size());
    }
    
    // this method is for test purpose
    public void showRecord()
    {
	for(RecordedGameListValue recordedGameListValue: listRecordedGame)
	{
	    //System.out.println("Time:" + recordedGameListValue.getTime() + ", Game sceen:" + recordedGameListValue.getStrGameScene());
	}
    }
    //

    /**
     * @return the recordingState
     */
    public RecordingState getRecordingState() 
    {
	return recordingState;
    }

    /**
     * @param recordingState the recordingState to set
     */
    public void setRecordingState(RecordingState recordingState) {
	this.recordingState = recordingState;
    }
}


class RecordedGameListValue implements Serializable
{
    private Long time; // time in miliseconds
    private String strGameScene;
    
    public RecordedGameListValue(Long time, String strGameScene)
    {
	this.time = time;
	this.strGameScene = strGameScene;	
    }

    /**
     * @return the time
     */
    public Long getTime() {
	return time;
    }

    /**
     * @return the strGameScene
     */
    public String getStrGameScene() 
    {
	return strGameScene;
    }
    
}

enum RecordingState implements Serializable
{
    STARTED, STOPPED;
}